<template>
  <div style="position:relative">
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :dataSource="list"
      :isColumnFilter="false"
      :isToperInfo="false"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getFwhdWxxmList, getFwhdSfList, getFwhdWxlxList, getFwhdGsdjList } from '@/api/repair/business/customer/activity.js';
export default {
  name: 'Wxxm',
  mixins: [dictionary],
  props: ['ACTIVITY_CODE'],
  data() {
    return {
      columns: this.createTable(),
      fetchParams: { xhrAbort: false },
      list: []
    };
  },
  created() {
    this.getFwhdSfList();
    this.getFwhdWxlxList();
    this.getFwhdGsdjList();
    this.getFwhdWxxmList(this.ACTIVITY_CODE);
    console.log('传来的CODE', this.ACTIVITY_CODE);
  },
  methods: {
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: '',
          sorter: true,
          render: props => {
            return <span>{}</span>;
          }
        },
        {
          title: '维修车型分组代码',
          dataIndex: 'MODEL_LABOUR_CODE',
          sorter: true
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_NAME',
          sorter: true
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filterItems: [],
          render: props => {
            return <span>{this.func(props.row.REPAIR_TYPE_CODE, 5)}</span>;
          }
        },

        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filterItems: [],
          render: props => {
            return <span>{this.func(props.row.CHARGE_PARTITION_CODE, 6)}</span>;
          }
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE_CODE',
          sorter: true,
          summationPrecision: 2,
          summation: true,
          filterItems: [],
          render: props => {
            return <span>{}</span>;
          }
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true
        },
        {
          title: '折扣后工时费',
          dataIndex: 'LABOUR_AMOUNT_DISCOUNT',
          sorter: true,
          summationPrecision: 2,
          summation: true
        }
      ];
    },
    async getFwhdWxxmList(row) {
      const res = await getFwhdWxxmList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list = res.rows;
      console.log('维修项目table', res);
    },
    async getFwhdSfList() {
      const res = await getFwhdSfList();
      this.columns[6].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
      console.log('收费区分', this.columns[6].filterItems);
    },
    async getFwhdWxlxList() {
      const res = await getFwhdWxlxList();
      this.columns[5].filterItems = res.map(x => ({ value: x.REPAIR_TYPE_CODE, text: x.REPAIR_TYPE_NAME }));
      console.log('项目维修类型', this.columns[5].filterItems);
    },
    async getFwhdGsdjList() {
      const res = await getFwhdGsdjList();
      this.columns[9].filterItems = res.map(x => ({ value: x.LABOUR_PRICE_CODE, text: x.LABOUR_PRICE }));
      console.log('工时单价', this.columns[9].filterItems);
    },
    func(val, num) {
      if (val) {
        const res = this.columns[num].filterItems.find(x => x.value == val);
        return res.text;
      }
    }
  }
};
</script>
